package com.weaponlin.domain.generic;

import java.util.EmptyStackException;

public class MA<E> {

    private Object[] elements;
    private int size = 0;
    private static final int DEFAULT_INITIAL_SIZE = 1 << 4;

    @SuppressWarnings("unchecked")
    public MA() {
        elements = new Object[DEFAULT_INITIAL_SIZE];
    }

    public void push(E e) {
        elements[size++] = e;
    }

    public E pop() {
        if (size <= 0) {
            throw new EmptyStackException();
        }
        @SuppressWarnings("unchecked")
        E e = (E) elements[--size];
        elements[size] = null;
        return e;
    }
}
